#include "CinDataMap.h"


CinDataMap *CinDataMap::mInstance = NULL;


CinDataMap::~CinDataMap()
{
    if (mInstance)
    {
        delete mInstance;
        mInstance = nullptr;
    }
    
}

CinDataMap* CinDataMap::GetInstance()
{
    if (!mInstance)
    {
        mInstance = new CinDataMap();
    }
    return mInstance;
}

CinDataMap::CinDataMap(/* args */)
{
}


DataItem CinDataMap::findDataByid(int fd)
{     
    DataItem item;
    item.m_nRecvSize = 0;
    std::unordered_map<int, DataItem>::iterator itr;
       
    if ((itr = mData.find(fd)) != mData.end())
    {
        return itr->second;
    }   
   
    return  item;
}


void CinDataMap::addData(int fd, DataItem item)
{
    mtx.lock(); 
    mData.insert(std::make_pair(fd, item));
    mtx.unlock();
}

void CinDataMap::removeData(int fd)
{
    mtx.lock(); 
    mData.erase(fd);
    mtx.unlock();
}